from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Button, Cancel, Row, ScrollingGroup, Select
from aiogram_dialog.widgets.text import Format

from src.presentation.tg_bot.dialogs.getters.users import user_orders_getter
from src.presentation.tg_bot.dialogs.widgets import LocaleText
from src.presentation.tg_bot.states import UserOrdersSG

from .handlers import back_to_status_select, display_order_details, display_orders

orders_history_window = Window(
    LocaleText("orders-history"),
    Row(
        Button(LocaleText("orders-active"), id="active", on_click=display_orders),
        Button(LocaleText("orders-archive"), id="archive", on_click=display_orders),
    ),
    Cancel(LocaleText("back-btn")),
    state=UserOrdersSG.orders_history,
)

orders_active_window = Window(
    LocaleText("orders-active"),
    ScrollingGroup(
        Select(
            Format("№{item.id} {item.summ}$ {item.was_created}"),
            "user_orders_sel",
            lambda order: order.id,
            "user_orders",
            on_click=display_order_details,
        ),
        width=1,
        height=4,
        id="useritemssel",
        hide_on_single_page=True,
    ),
    Button(
        LocaleText("back-btn"),
        id="back_to_status_select",
        on_click=back_to_status_select,
    ),
    state=UserOrdersSG.user_orders_active,
    getter=user_orders_getter,
)

orders_archive_window = Window(
    LocaleText("orders-archive"),
    ScrollingGroup(
        Select(
            Format("{item.summ}$ {item.was_created}"),
            "user_orders_sel",
            lambda order: order.id,
            "user_orders",
            on_click=display_order_details,
        ),
        width=1,
        height=4,
        id="useritemssel",
        hide_on_single_page=True,
    ),
    Button(
        LocaleText("back-btn"),
        id="back_to_status_select",
        on_click=back_to_status_select,
    ),
    state=UserOrdersSG.user_orders_archive,
    getter=user_orders_getter,
)

orders_history_dialog = Dialog(
    orders_history_window,
    orders_active_window,
    orders_archive_window,
)
